<template>
  <div class="tableList">
    <header>
      <span style="color:#909399">{{ headerTitle }}</span>
      <span>{{ headerRight }}</span>
    </header>
    <table cellspacing="0" align="center" cellpadding="0">
      <tr v-for="rowi in row" :key="rowi">
        <td v-for="coli in col" :key="coli">
          <div v-if="data&&data.length" class="table">
            <div ref="prop" class="prop">
              <span v-if="(rowi-1)*col+coli-1<data.length">{{ prop?data[(rowi-1)*col+coli-1][prop]:data[(rowi-1)*col+coli-1] }}</span>
            </div>
          </div>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: 'TableList',
  props: {
    headerTitle: String,
    headerRight: String,
    prop: String,
    col: {
      type: Number,
      default: 6
    },
    data: null
  },
  data() {
    return {
      row: 1
    }
  },
  watch: {
    data(val) {
      if (val && val.length) {
        this.row = val ? Math.ceil(val.length / this.col) : 1
      }
      this.$forceUpdate()
    }
  },
  created() {
    this.row = this.data ? Math.ceil(this.data.length / this.col) : 1
  }
}
</script>

<style lang="scss" scoped>
.tableList{
  header{
    min-height: 48px;
    box-sizing: border-box;
    padding: 0 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #F9FAFC;
    font-weight: bold;
    font-size: 16px;
    border: 1px solid $border_color;/*no*/
    border-bottom: none;
  }
}
table{
  width: 100%;
  margin: 0;
  border-color: $border_color !important;
  background: #fff;
  border-top: 1px solid $border_color;/*no*/
  border-left: 1px solid $border_color;/*no*/
  tr{
    display: flex;
    min-height: 48px;
    td{
      flex:1;
      border-bottom: 1px solid $border_color;/*no*/
      border-right: 1px solid $border_color;/*no*/
    }
  }
}
.table{
  height: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  .prop{
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    box-sizing: border-box;
    padding: 10px;
  }
  .prop{
    flex: 1 1 auto;
  }
}
</style>

